/**
 * Copyright (c) 2007,中企动力华南研发中心<br>
 * All rights reserved.
 */
package com.ce.pms.charge.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ce.pms.base.service.impl.PmsBaseServiceImpl;
import com.ce.pms.charge.dao.IAccountDao;
import com.ce.pms.charge.dao.IBusinessCodeDao;
import com.ce.pms.charge.dao.IChargeUnpaidStatisticsDao;
import com.ce.pms.charge.dao.IChargeVoucherDao;
import com.ce.pms.charge.dao.IPeriodDao;
import com.ce.pms.charge.dao.IPrePaySchDao;
import com.ce.pms.charge.dao.ISubAccountDao;
import com.ce.pms.charge.dao.ITransactionDao;
import com.ce.pms.charge.dao.ITransactionRelationDao;
import com.ce.pms.charge.model.BusinessCodeDomain;
import com.ce.pms.charge.model.ChargeUnpaidStatisticsDO;
import com.ce.pms.charge.model.CreditTransDomain;
import com.ce.pms.charge.model.DebitTransDomain;
import com.ce.pms.charge.model.PeriodDomain;
import com.ce.pms.charge.model.SchDetail;
import com.ce.pms.charge.model.VoucherDomain;
import com.ce.pms.charge.service.IPrePayOffsetService;
import com.ce.pms.charge.vo.PrePayOffsetSearchVO;
import com.ce.pms.charge.vo.PrePayOffsetTransVO;
import com.ce.pms.charge.vo.PrePayOffsetVO;
import com.ce.pms.charge.vo.TransactionRelationBean;
import com.ce.pms.common.dao.ISecUserDao;
import com.ce.pms.common.model.SysInfo;
import com.ce.pms.common.model.SysrefcodeDO;
import com.ce.pms.common.util.BigDecimalUtil;
import com.ce.pms.customer.dao.IProRightDao;
import com.ce.pms.exception.BusinessException;
import com.ce.pms.house.dao.IHouseDao;
import com.sitechasia.webx.core.support.Page;

/**
 * 功能描述：预交款抵冲<br>
 * @author 罗军林 创建日期：2008-9-26
 */
public class PrePayOffsetServiceImpl extends PmsBaseServiceImpl implements IPrePayOffsetService {
	private final int PAGE_SIZE=1000;
	private final String PRIFIX="JFT";

	private IAccountDao accountDao;
	private ISubAccountDao subAccountDao;
	private ITransactionDao transactionDao;
	private ITransactionRelationDao transactionRelationDao;
	private IChargeUnpaidStatisticsDao chargeUnpaidStatisticsDao;
	private IPrePaySchDao prePaySchDao;
	private IBusinessCodeDao businessCodeDao;
	private IPeriodDao periodDao;
	private IChargeVoucherDao chargeVoucherDao;
	private IHouseDao houseDao;
	private IProRightDao proRightDao;
	private ISecUserDao secUserDao;
	private Integer voucherSeq=0;

	/**
	 * 线程成员变量:参与抵冲的交易列表,主键为房号ID
	 */
	private ThreadLocal<Map<Long,ChargeUnpaidStatisticsDO>> prePayTransactionList=new ThreadLocal<Map<Long,ChargeUnpaidStatisticsDO>>();

	/**
	 * 线程成员变量：能抵冲的交易列表 KEY 房号 , VALUE 交易ID列表
	 */
	private ThreadLocal<Map<Long,List<Long>>> arTranDetail=new ThreadLocal<Map<Long,List<Long>>>();

	public Page queryPrePay(PrePayOffsetSearchVO searchVO) {
		return accountDao.queryPrePay(searchVO);
	}

	/**
	 * 功能描述:根据帐户ID查询预交帐户信息<br>
	 * @param houseId
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-10-7<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public PrePayOffsetVO findPrePayOffsetByAccountId(Long accountId){
		this.checkParameterIsNull(accountId, "charge:accountId_not_null");
		return accountDao.findPrePayOffsetByAccountId(accountId);
	}

	/**
	 * 功能描述:查询指定帐户的预交款的交易<br>
	 * @param accountId
	 * @param pageNo
	 * @param pageSize
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-10-14<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public Page queryPrePayTrans(Long accountId,int pageNo,int pageSize){
		Page page= transactionDao.queryPrePayTrans(accountId, pageNo, pageSize);
		List<CreditTransDomain> list=page.getResult();

		List<PrePayOffsetTransVO> tempList=new ArrayList<PrePayOffsetTransVO>();
		for(CreditTransDomain item : list){
			PrePayOffsetTransVO prePayVO=new PrePayOffsetTransVO();
			prePayVO.setTransName( item.getBusinessCode().getBizCode()+"-"+item.getBusinessCode().getDescription());

			if(SysrefcodeDO.FEE_TRANSACTION_CLAZZ_PRERECEIVABLES.equals(item.getClazz())){
				prePayVO.setClazzName(SysrefcodeDO.CHARGE_STRING);
			}else if(SysrefcodeDO.FEE_TRANSACTION_CLAZZ_TOUCH.equals(item.getClazz())){
				prePayVO.setClazzName(SysrefcodeDO.PREPAY_STRING);
			}
			prePayVO.setPrice(item.getCredit());
			prePayVO.setHandTime( item.getSysInfo().getSysDate());
			if(null!=item.getVoucher()){
				prePayVO.setVoucherNumber(item.getVoucher().getVoucherNumber());
				prePayVO.setFilledDate(item.getVoucher().getChargeDate());
			}
			prePayVO.setRemark(item.getRemark());
			prePayVO.setOperatorName(secUserDao.queryUserNameById(item.getSysInfo().getCreator()));
			tempList.add(prePayVO);
		}

		page.setResult(tempList);
		return page;
	}

	/**
	 * 功能描述:预交款抵冲<br>
	 * @param userId
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-26<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public boolean prePayOffset(Long userId){
		Long startDate=System.currentTimeMillis();
		logger.info("开始预交款抵冲...");
		int pageNo=1;
		voucherSeq=chargeVoucherDao.getMaxVoucherNumSeqByType(PRIFIX);//通知单序号
		BusinessCodeDomain prePayBusinessCode=businessCodeDao.findBusinessCodeByParaDef(SysrefcodeDO.PREPAYOFFSET_PAID_CODE);
		if(null==prePayBusinessCode)throw new BusinessException("charge:businesscode_not_found_exception",BusinessException.ERROR);

		Map<Long,List<SchDetail>> preSchMap=prePaySchDao.queryAllSchDetail();
		List<TransactionRelationBean> transactionRelationList=new ArrayList<TransactionRelationBean>();
		SysInfo currentSysInfo=createInfo(userId);//当前用户信息
		PeriodDomain currentPeriod= periodDao.queryCurrentPeriod();//当前收费周期

		List<Long> arTransactionIdList=new ArrayList<Long>();
		Map<Long,BigDecimal> prePaySubAccountBalanceMap=new HashMap<Long, BigDecimal>();
		Map<Long,BigDecimal> arSubAccountBalanceMap=new HashMap<Long, BigDecimal>();
		List<ChargeUnpaidStatisticsDO> unpaidStatistList=null;
		List<ChargeUnpaidStatisticsDO> tempList=new ArrayList<ChargeUnpaidStatisticsDO>();//临时
		initPrepayTransactionList();
		initArTranDetail();
		do{
			unpaidStatistList=chargeUnpaidStatisticsDao.queryUnpaidStatistics(pageNo++,PAGE_SIZE);
			for(int i=0;unpaidStatistList!=null && i<unpaidStatistList.size();i++){
				ChargeUnpaidStatisticsDO item = unpaidStatistList.get(i);
				if( isSameAccountPeriodAsPrev(unpaidStatistList,i)  && i==PAGE_SIZE-1){
						tempList.add(item);
						unpaidStatistList=chargeUnpaidStatisticsDao.queryUnpaidStatistics(pageNo++,PAGE_SIZE);
						i=-1;
				}else if( (i>0 && ! (isSameAccountPeriodAsPrev(unpaidStatistList,i) )) ||
						( i==0 && !isSameAccountAndPeriod(tempList, item)) ){
					offsetCore(userId, prePayBusinessCode, preSchMap, transactionRelationList, arTransactionIdList, prePaySubAccountBalanceMap, arSubAccountBalanceMap, tempList);
					tempList.clear();
					tempList.add(item);
				}else if(unpaidStatistList.size()<PAGE_SIZE && i==(unpaidStatistList.size()-1)){
					tempList.add(item);
					offsetCore(userId, prePayBusinessCode, preSchMap, transactionRelationList, arTransactionIdList, prePaySubAccountBalanceMap, arSubAccountBalanceMap, tempList);
					tempList.clear();
				}else{
					tempList.add(item);
				}
			}

		}while(unpaidStatistList!=null && unpaidStatistList.size()==PAGE_SIZE);

		//当临时表中还有值时，需要再抵冲一次。
		if(null!=tempList && tempList.size()>0){
			offsetCore(userId, prePayBusinessCode, preSchMap, transactionRelationList, arTransactionIdList, prePaySubAccountBalanceMap, arSubAccountBalanceMap, tempList);
			tempList.clear();
		}
		checkOffsetData(prePaySubAccountBalanceMap, arSubAccountBalanceMap);
		synchronized (this) {
			saveTrans(currentSysInfo, prePayBusinessCode, transactionRelationList,currentPeriod);
			transactionRelationDao.insertTransactionRelationBatch(transactionRelationList);
			transactionDao.updateTransactionStatus(arTransactionIdList, SysrefcodeDO.FEE_TRANSACTION_STATUZ_PAYED);
			transactionDao.updateTransactionStatusByMasterId(arTransactionIdList);
			subAccountDao.updateSubAccountBalanceBatch(prePaySubAccountBalanceMap);
			subAccountDao.updateSubAccountBalanceBatchSub(arSubAccountBalanceMap);
		}
		logger.info("预交款抵冲完成，所花时间为："+(System.currentTimeMillis()-startDate));
		return true;
	}

	/**
	 * 功能描述:三个列表的大小应一致，如果不一致将抛出异常<br>
	 * @param prePaySubAccountBalanceMap
	 * @param arSubAccountBalanceMap<br>
	 * Create author:罗军林<br>
	 * Create on:2008-11-21<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void checkOffsetData(Map<Long, BigDecimal> prePaySubAccountBalanceMap, Map<Long, BigDecimal> arSubAccountBalanceMap) {
		if( arSubAccountBalanceMap.size()!=prePayTransactionList.get().size()){
			throw new BusinessException("charge:offset_exception");
		}
	}

	/**
	 * 功能描述:item的收费周期和帐户是否和tempList的最后一项相同，如果相同返回true，如果tempList为空或为0也将返回true<br>
	 * @param tempList
	 * @param item
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-11-10<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private boolean isSameAccountAndPeriod(List<ChargeUnpaidStatisticsDO> tempList,ChargeUnpaidStatisticsDO item){
		if(null==tempList || tempList.size()==0){
			return true;
		}else{
			return item.getChargeAccountId().equals(tempList.get(tempList.size()-1).getChargeAccountId())
			&& item.getPeriodId().equals(tempList.get(tempList.size()-1).getPeriodId());
		}
	}
	/**
	 * 功能描述:抵冲核心<br>
	 * @param userId
	 * @param prePayBusinessCode
	 * @param preSchMap
	 * @param transactionRelationList
	 * @param arTransactionIdList
	 * @param prePaySubAccountBalanceMap
	 * @param arSubAccountBalanceMap
	 * @param tempList
	 * Create author:罗军林<br>
	 * Create on:2008-10-7<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void offsetCore(Long userId, BusinessCodeDomain prePayBusinessCode, Map<Long, List<SchDetail>> preSchMap, List<TransactionRelationBean> transactionRelationList, List<Long> arTransactionIdList, Map<Long, BigDecimal> prePaySubAccountBalanceMap, Map<Long, BigDecimal> arSubAccountBalanceMap, List<ChargeUnpaidStatisticsDO> tempList) {
		for(List<SchDetail> schDetailList : preSchMap.values()){
			for(SchDetail schDetail : schDetailList){
				for(ChargeUnpaidStatisticsDO temp : tempList){
					if(getOffsetTransactionChargeItemId(temp).equals( schDetail.getChargeItem().getKeyword() ) &&
							temp.getPrePaySchemeId().equals(schDetail.getPrePaySch().getPrePaySchId()) ){
						BigDecimal preBalance=prePaySubAccountBalanceMap.get(temp.getPrePayAccountId());
						if(null==preBalance){
							preBalance=temp.getPrePayBalance();
							prePaySubAccountBalanceMap.put(temp.getPrePayAccountId(), preBalance);
						}
						if(BigDecimal.ZERO.subtract(preBalance).compareTo(temp.getTotalAmt())>=0){
							preBalance=preBalance.add(temp.getTotalAmt());

							prePaySubAccountBalanceMap.put(temp.getPrePayAccountId(), preBalance);

							arSubAccountBalanceMap.put(temp.getChargeAccountId(),
									BigDecimalUtil.addBigDecimal( temp.getTotalAmt(), arSubAccountBalanceMap.get(temp.getChargeAccountId())) );

							addPrepayTranToList(temp.clone());

							arTransactionIdList.add(temp.getMasterTransId());

							addArTranDetail(temp.getHouseId(),temp.getId().getTransId());

						//	logger.info("+房号："+temp.getHouseId()+",方案："+schDetail.getPrePaySch().getPrePaySchId()+",收费项目："+schDetail.getChargeItem().getItemName());
						}
					}
				}
			}
		}
	}

	/**
	 * 功能描述:将该房号的应收交易ID增加至缓存<br>
	 * @param houseId  房号ID
	 * @param arTranId 应收交易ID<br>
	 * Create author:罗军林<br>
	 * Create on:2008-11-10<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void addArTranDetail(Long houseId,Long arTranId){
		List<Long> temp= arTranDetail.get().get(houseId);
		if(null!=temp){
			temp.add(arTranId);
		}else{
//			Map<Long,List<Long>> houseMap=new HashMap<Long, List<Long>>();
			List<Long> artranList=new ArrayList<Long>();
			artranList.add(arTranId);
			arTranDetail.get().put(houseId, artranList);
		}
	}

	/**
	 * 功能描述:取得抵冲交易的收费项目ID，如果是附属交易没有项目ID，将返回其主交易的项目ID<br>
	 * @param temp
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-11-8<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private Long getOffsetTransactionChargeItemId(ChargeUnpaidStatisticsDO temp) {
		if(null==temp.getChargeItemId()){
			DebitTransDomain debitTran=(DebitTransDomain)transactionDao.findById(temp.getMasterTransId());
			if(null==debitTran){
				throw new BusinessException("charge:staid_not_null",BusinessException.ERROR);
			}
			return debitTran.getStaVersion().getChargeSta().getChargeItem().getKeyword();
		}else{
			return temp.getChargeItemId();
		}
	}

	/**
	 * 功能描述:以房间为单位，对每次抵冲的费用进行累计<br>
	 * @param temp<br>
	 * Create author:罗军林<br>
	 * Create on:2008-11-6<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void addPrepayTranToList(ChargeUnpaidStatisticsDO temp) {
		ChargeUnpaidStatisticsDO prepayTran=prePayTransactionList.get().get(temp.getHouseId());
		if(null==prepayTran){
			prePayTransactionList.get().put(temp.getHouseId(), temp);
		}else{
			prepayTran.setTotalAmt( prepayTran.getTotalAmt().add(temp.getTotalAmt()) );
		}
	}

	/** 功能描述:  <br>
	 *
	 *
	 * Create author:罗军林 <br>
	 * Create on:2008-11-6  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	*/
	private void initPrepayTransactionList() {
//		if(null==prePayTransactionList.get()){
			prePayTransactionList.set(new HashMap<Long, ChargeUnpaidStatisticsDO>());
//		}
	}

	/**
	 * 功能描述:初始化应收交易的详细列表<br>
	 * <br>
	 * Create author:罗军林<br>
	 * Create on:2008-11-10<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void initArTranDetail(){
//		if(null==arTranDetail.get()){
			arTranDetail.set(new HashMap<Long, List<Long>>());
//		}
	}

	/**
	 * 功能描述:保存一组交易。包括：一张凭证、一笔支付交易、一笔抵冲交易、及这组交易的关系<br>
	 * @param userId
	 * @param prePayBusinessCode
	 * @param transactionRelationList
	 * @param temp<br>
	 * Create author:罗军林<br>
	 * Create on:2008-11-6<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void saveTran(SysInfo sysInfo, BusinessCodeDomain prePayBusinessCode, List<TransactionRelationBean> transactionRelationList, ChargeUnpaidStatisticsDO temp,PeriodDomain currentPeriod) {
		//新增凭证
		VoucherDomain payVoucher = addVoucher(++voucherSeq, temp,sysInfo);

		//新增支付交易
		CreditTransDomain payTrans = addPayTrans(prePayBusinessCode, temp, payVoucher, sysInfo, currentPeriod);

		//新增抵冲交易
		CreditTransDomain offsetTrans = addOffsetTrans(prePayBusinessCode, temp, sysInfo, currentPeriod);

		//建立支付交易同所缴应收交易的关系
		addPayArTrans(temp.getHouseId(), payTrans, transactionRelationList);

		//建立抵冲交易同支付交易的关系
		transactionRelationList.add(addOffsetPayTrans(payTrans, offsetTrans));
	}

	/**
	 * 功能描述:以房间为单位，保存交易信息<br>
	 * @param userId
	 * @param prePayBusinessCode
	 * @param transactionRelationList<br>
	 * Create author:罗军林<br>
	 * Create on:2008-11-6<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void saveTrans(SysInfo sysInfo, BusinessCodeDomain prePayBusinessCode, List<TransactionRelationBean> transactionRelationList,PeriodDomain currentPeriod){
		for(ChargeUnpaidStatisticsDO prepayTran : prePayTransactionList.get().values()){
			saveTran(sysInfo, prePayBusinessCode, transactionRelationList, prepayTran, currentPeriod);
		//	logger.info("房号ID为"+prepayTran.getHouseId()+"的房间产生了一笔交易.");
		}
	//	logger.info("共产生了"+prePayTransactionList.get().size()+"笔交易。");
	}

	/**
	 * 功能描述:当前项的子帐户、收费周期是否和上一个相同<br>
	 * @param unpaidStatistList
	 * @param index
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-10-6<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private boolean isSameAccountPeriodAsPrev(List<ChargeUnpaidStatisticsDO> unpaidStatistList, int index){
		return index>0 && unpaidStatistList.get(index).getChargeAccountId().equals(unpaidStatistList.get(index-1).getChargeAccountId())
		&& unpaidStatistList.get(index).getPeriodId().equals(unpaidStatistList.get(index-1).getPeriodId());
	}


	/**
	 * 功能描述: 新增一个收费凭证<br>
	 * @param voucherSeq
	 * @param temp
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-28<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private VoucherDomain addVoucher(int voucherSeq, ChargeUnpaidStatisticsDO temp,SysInfo sysinfo) {
		VoucherDomain payVoucher=new VoucherDomain();
		payVoucher.setHouse(houseDao.loadById(temp.getHouseId()));
		payVoucher.setProRight(proRightDao.loadById(temp.getProRightId()));
		payVoucher.setVoucherNumber(buildFlowNumber(PRIFIX,temp.getChargePrecinctId(),voucherSeq));
		payVoucher.setSum(temp.getTotalAmt());
		payVoucher.setChargeDate(sysinfo.getSysDate());
		payVoucher.setStatuz(SysrefcodeDO.FEE_VOUCHER_STATUZ_NEW);
		payVoucher.setSysInfo(sysinfo);
		chargeVoucherDao.saveObject(payVoucher);
		return payVoucher;
	}

	/**
	 * 功能描述:新增抵冲交易<br>
	 * @param prePayBusinessCode
	 * @param temp
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-28<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private CreditTransDomain addOffsetTrans(BusinessCodeDomain prePayBusinessCode, ChargeUnpaidStatisticsDO temp,SysInfo sysinfo,PeriodDomain currentPeriod) {
		CreditTransDomain offsetTrans=new CreditTransDomain();
		offsetTrans.setBindingAccount(subAccountDao.loadById(temp.getPrePayAccountId()));
		offsetTrans.setBusinessCode(prePayBusinessCode);
		offsetTrans.setCredit( BigDecimal.ZERO.subtract(temp.getTotalAmt()) );
		offsetTrans.setClazz(SysrefcodeDO.FEE_TRANSACTION_CLAZZ_TOUCH);
		offsetTrans.setPeriod(currentPeriod);
		offsetTrans.setSysInfo(sysinfo);
		transactionDao.saveObject(offsetTrans);
		return offsetTrans;
	}

	/**
	 * 功能描述:新增支付交易<br>
	 * @param prePayBusinessCode
	 * @param temp
	 * @param payVoucher
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-28<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private CreditTransDomain addPayTrans(BusinessCodeDomain prePayBusinessCode, ChargeUnpaidStatisticsDO temp, VoucherDomain payVoucher,SysInfo sysinfo,PeriodDomain currentPeriod) {
		CreditTransDomain payTrans=new CreditTransDomain();
		payTrans.setBindingAccount(subAccountDao.loadById(temp.getChargeAccountId()));
		payTrans.setBusinessCode(prePayBusinessCode);
		payTrans.setCredit(temp.getTotalAmt());
		payTrans.setClazz(SysrefcodeDO.FEE_TRANSACTION_CLAZZ_MAINPAY);
		payTrans.setPeriod( currentPeriod );
		payTrans.setVoucher(payVoucher);
		payTrans.setSysInfo(sysinfo);
		transactionDao.saveObject(payTrans);
		return payTrans;
	}

//	/**
//	 * 功能描述:得到当前房间所在的收费周期<br>
//	 * @param temp
//	 * @return<br>
//	 * Create author:罗军林<br>
//	 * Create on:2008-11-6<br>
//	 * Edit author:<br>
//	 * Edit on:<br>
//	 * Why:<br>
//	 */
//	private PeriodDomain getPeriodByhouseId(Long houseId) {
//		return periodDao.queryCurrentPeriod();
//	}

	/**
	 * 功能描述:建立支付交易同所缴应收交易的关系<br>
	 * @param houseId
	 * @param payTrans
	 * @param transactionRelationList
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-28<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void addPayArTrans(Long houseId, CreditTransDomain payTrans,final List<TransactionRelationBean> transactionRelationList) {
		for(Long arTranId : arTranDetail.get().get(houseId)){
			TransactionRelationBean payArTr=new TransactionRelationBean();
			payArTr.setMasterTransactionId(payTrans.getTransactionId());
			payArTr.setRelationTransactionid(arTranId);
			payArTr.setRelationType(SysrefcodeDO.FEE_TRANSACTION_CLAZZ_MAINPAY);
			transactionRelationList.add(payArTr);
		}
	}

	/**
	 * 功能描述:建立抵冲交易同支付交易的关系<br>
	 * @param payTrans
	 * @param offsetTrans
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-28<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private TransactionRelationBean addOffsetPayTrans(CreditTransDomain payTrans, CreditTransDomain offsetTrans) {
		TransactionRelationBean offsetPayTr=new TransactionRelationBean();
		offsetPayTr.setMasterTransactionId(payTrans.getTransactionId());
		offsetPayTr.setRelationTransactionid(offsetTrans.getTransactionId());
		offsetPayTr.setRelationType(SysrefcodeDO.FEE_TRA_R_TRA_RELATION_TYPE_TOUCH);
		return offsetPayTr;
	}

	public void setAccountDao(IAccountDao accountDao) {
		this.accountDao = accountDao;
	}

	public void setBusinessCodeDao(IBusinessCodeDao businessCodeDao) {
		this.businessCodeDao = businessCodeDao;
	}

	public void setChargeUnpaidStatisticsDao(
			IChargeUnpaidStatisticsDao chargeUnpaidStatisticsDao) {
		this.chargeUnpaidStatisticsDao = chargeUnpaidStatisticsDao;
	}

	public void setChargeVoucherDao(IChargeVoucherDao chargeVoucherDao) {
		this.chargeVoucherDao = chargeVoucherDao;
	}

	public void setHouseDao(IHouseDao houseDao) {
		this.houseDao = houseDao;
	}

	public void setPeriodDao(IPeriodDao periodDao) {
		this.periodDao = periodDao;
	}

	public void setPrePaySchDao(IPrePaySchDao prePaySchDao) {
		this.prePaySchDao = prePaySchDao;
	}

	public void setProRightDao(IProRightDao proRightDao) {
		this.proRightDao = proRightDao;
	}

	public void setSubAccountDao(ISubAccountDao subAccountDao) {
		this.subAccountDao = subAccountDao;
	}

	public void setTransactionDao(ITransactionDao transactionDao) {
		this.transactionDao = transactionDao;
	}

	public void setTransactionRelationDao(
			ITransactionRelationDao transactionRelationDao) {
		this.transactionRelationDao = transactionRelationDao;
	}

	public void setSecUserDao(ISecUserDao secUserDao) {
		this.secUserDao = secUserDao;
	}

}
